public class Main2 {
    public static void main(String[] args) {
        //2.设有仿射变换对一个明文加密得到的密文为：
        //EDSGICKXHUKLZVEQZVKXWKZUKVCUH
        //又已知明文的前两个字符是“IF”。对该密文解密。
        String str = "EDSGICKXHUKLZVEQZVKXWKZUKVCUH";
        //1.计算出仿射变换的解密方程中的参数
        char ch0 = str.charAt(0);
        char ch1 = str.charAt(1);
        int a = 0;
        int b = 0;
        for(a = 0; a < 26; a++) {
            boolean flag = false;
            for(b = 0; b < 26; b++) {
                char chTmp0 = (char)('A' + (a * ch0 + b) % 26);
                char chTmp1 = (char)('A' + (a * ch1 + b) % 26);
                if(chTmp0 == 'I' && chTmp1 == 'F') {
                    flag = true;
                    break;
                }
            }
            if(flag) {
                break;
            }
        }
        System.out.print("IF");
        //2.利用解密方程得出明文
        for(int i = 2; i < str.length(); i++) {
            char ch = str.charAt(i);
            System.out.print((char)('A' + (a * ch + b) % 26));
        }
        //IF YOU CAN READ THIS THANK A TEAHCER
        //if you can read this, thank a teahcer
    }
}
